package com.rjj.wlqq.listen.interceptor;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringBootConfiguration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * 拦截器注册
 */
@SpringBootConfiguration
public class InterceptorConfig implements WebMvcConfigurer {


    /**
     * 注册拦截器
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getSecurityInterceptor())
                //.addPathPatterns("/*")
        ;
    }


    /**
     * 这里两种方式
     * 1，通过下边这种new  方式
     * 2，通过注入的方式
     *  <pre>
     *         @Resource
     *         private MethodInterceptor methodInterceptor;
     *   </pre>
     */
    public HandlerInterceptor getSecurityInterceptor() {
        return new MethodInterceptor();
    }
}
